#ifndef _PICK_FACTOR_H_
#define _PICK_FACTOR_H_

struct PickFactor
{
public:

    const char* getName()
    {
        const static char name[] = "PickFactor"; 
        return name;
    }
    
    template
    <
        typename SignalSystem
    >
    double operator()(SignalSystem& system)
    {
        using namespace std;
       
        double sum = 0;
        double splash = 0;
        
        for (int i = 0; i < system.size() ; ++i)
        {
            vector<double> rslt(system[i].size());
            
            transform(
                system[i].begin(), system[i].end(),
                rslt.begin(),
                absolute<complex<double>,double>()
            );
        
            std::binder2nd
            <
                power<int, double>
            >
            power2(
                power<int, double>(),
                2
            );
        
            splash = max(splash, *max_element(rslt.begin(), rslt.end()));
            
            transform(
                rslt.begin(), rslt.end(),
                rslt.begin(),
                power2
            );
      
            sum =
                accumulate(
                    rslt.begin(), rslt.end(),
                    sum
                );
        }
        
        sum = sqrt(sum / (system.size() * system[0].size()));
        return splash / sum;
    }
};

#endif // _PICK_FACTOR_H_
